/**
 * 作者：陈文斌 on 2019/1/8.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/main_scoped_model.dart';
import 'package:crm/model/ClientManager/client_info_model.dart';
import 'package:crm/model/ClientManager/contact_info_model.dart';
import 'package:crm/viewModel/ClientManager/client_manager_view_model.dart';
import 'package:crm/component/ClientManager/AddClient/client_info_edit_section.dart';
import 'package:crm/component/ClientManager/AddClient/add_client_contact_list_section.dart';

class AddClientListSection extends StatefulWidget {
  /// 客户类型，默认为正式客户(customerType = 0)
  final int clientType;

  @override
  AddClientListSection({
    Key key,
    this.clientType = 0,
  }) : super(key: key);

  State<StatefulWidget> createState() => _AddClientListSectionState();
}

class _AddClientListSectionState extends State<AddClientListSection> {
  ClientInfoModel _client;

  @override
  Widget build(BuildContext context) {
    MainModel clientManagerSM = MainModel().of(context);
    _client = clientManagerSM.client ?? ClientInfoModel.fromJson({});

    Widget _saveButtonSection = Container(
      width: AppScreen.setWidth(318),
      height: 40,
      margin: EdgeInsets.fromLTRB(
        AppScreen.setWidth(28),
        100,
        AppScreen.setWidth(29),
        20,
      ),
      decoration: BoxDecoration(
        color: AppColors.MainColor,
        borderRadius: BorderRadius.circular(20),
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(20),
        child: MaterialButton(
          onPressed: () {
            ClientManagerVM().addClient(
              context,
              client: _client,
              contacts: MainModel().of(context).contactsInfoList,
              customerType: widget.clientType,
            );
          },
          child: Text(
            '保存',
            style: TextStyle(
              color: Colors.white,
              fontSize: AppFontSizes.Font17,
              fontFamily: AppFontFamilies.PingFangSC,
            ),
          ),
        ),
      ),
    );

    return Expanded(
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Padding(padding: EdgeInsets.only(top: 5)),
            ClientInfoEditSection(
              client: _client,
            ),
            AddClientContactListSection(),
            _saveButtonSection,
          ],
        ),
      ),
    );
  }
}
